package com.meida.module.bus.provider.controller;

import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaUpdate;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.bus.client.entity.BusMaterialPackage100;
import com.meida.module.bus.client.entity.BusMaterialPlan200;
import com.meida.module.bus.provider.service.BusMaterialPackage100Service;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 100分包控制器
 *
 * @author flyme
 * @date 2020-10-10
 */
@RestController
@RequestMapping("/bus/bmp/")
public class BusMaterialPackage100Controller extends BaseController<BusMaterialPackage100Service, BusMaterialPackage100> {

    @ApiOperation(value = "100分包-分页列表", notes = "100分包分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "100分包-分页列表", notes = "100分包分页列表")
    @GetMapping(value = "common/page")
    public ResultBody pageList1(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "100分包-列表", notes = "100分包列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "100分包-添加", notes = "添加100分包")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "100分包-更新", notes = "更新100分包")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "100分包-删除", notes = "删除100分包")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "100分包-详情", notes = "100分包详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    /**
     * 导出100分包统计
     *
     * @param params
     * @param request
     * @param response
     */
    @PostMapping(value = "export")
    public void export(@RequestParam(required = false) Map params, HttpServletRequest request, HttpServletResponse response) {
        bizService.export(params, request, response, "100分包统计", "100分包统计表");
    }


    @ApiOperation(value = "100分包-首页分页列表", notes = "100分包首页分页列表")
    @GetMapping(value = "indexPage")
    public ResultBody indexPageList(@RequestParam(required = false) Map params) {
        params.put("handlerName", "adminPackage100IndexPageListHandler");
        return bizService.pageList(params);
    }

    @ApiOperation(value = "100分包-修正", notes = "100分包-修正")
    @PostMapping(value = "copyAndUpdate")
    public ResultBody copyAndUpdate(@RequestParam(required = false) Map params) {
        return bizService.copyAndUpdate(params);
    }

    @ApiOperation(value = "100分包-合并", notes = "100分包-合并")
    @PostMapping(value = "merge100")
    public ResultBody merge100(@RequestParam(required = false) Map params) throws Exception {
        return bizService.subMerge100OaCheck(params);
    }

    @ApiOperation(value = "100分包-分承包合同下达", notes = "100分包-分承包合同下达")
    @PostMapping(value = "getSrmPms05Req")
    public ResultBody getSrmPms05Req(@RequestParam(required = false) Map params) throws Exception {
        return bizService.getSrmPms05Req(params);
    }

    @ApiOperation(value = "100分包-转存200", notes = "100分包-转存200")
    @PostMapping(value = "archive200")
    public ResultBody archive200(@RequestParam(required = false) Map params) {
        return bizService.subArchive200OaCheck(params);
    }


    @ApiOperation(value = "100分包-导出模板", notes = "100分包-导出模板")
    @PostMapping(value = "export100Template")
    public void exportTemplate(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) Map params) {
        bizService.export(params, request, response, "100分包模板表", "100分包模板表", "busMaterialPackage100ExportHandler");
    }


    @ApiOperation(value = "100分包-导入数据", notes = "100分包-导入数据")
    @PostMapping(value = "import100UpdateData")
    public ResultBody import100UpdateData(@RequestParam(required = false) Map params, @RequestParam("file") MultipartFile file) {
        ResultBody resultBody = bizService.importOnUpdateBusMaterialPackage100Data(file, params);
        return resultBody;
    }

    @ApiOperation(value = "100分包-导入数据", notes = "100分包-导入数据")
    @PostMapping(value = "import100AddData")
    public ResultBody import100AddData(@RequestParam(required = false) Map params, @RequestParam("file") MultipartFile file) {
        ResultBody resultBody = bizService.importOnAddBusMaterialPackage100Data(file, params);
        return resultBody;
    }

    @ApiOperation(value = "100分包-获取历史版本", notes = "100分包-获取历史版本")
    @GetMapping(value = "selectVersionList")
    public ResultBody selectVersionList(@RequestParam(required = false) Map params) {
        List<EntityMap> entityMapList = bizService.selectVersionList(params);
        return ResultBody.ok().data(entityMapList);
    }

    @ApiOperation(value = "判断材料行是否存在变更中待审核的数据", notes = "判断材料行是否存在变更中待审核的数据")
    @GetMapping(value = "checkUnderReview")
    public ResultBody checkHasUnderReviewRecord(@RequestParam Long materialPackage100Id) {
        CriteriaUpdate<BusMaterialPackage100> cu = new CriteriaUpdate();
        cu.eq("parentId", materialPackage100Id);
        cu.eq("applayStatus", 1);//审批中
        int count = bizService.count(cu);
        if(count > 0) {
            return ResultBody.ok().data("Y");
        }
        return ResultBody.ok().data("N");
    }
}
